package com.gf.help.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import com.gf.common.util.DateFormater;
import com.gf.help.model.Question;

public class QuestionMapper implements RowMapper<Question> {

	private final static String QUESTION_ID = "id";
	private final static String ASKER_ID = "askerId";
	private final static String ASKER_NAME = "askerName";
	private final static String QUESTION_TITLE = "title";
	private final static String QUESTION_CONTENT = "content";
	private final static String PUBLISHTIME = "publishTime";
	private final static String READ_COUNT="readCount";
	private final static String REPLY_COUNT="replyCount";
	private final static String ASKERPORTRAIT="askerPortrait";
	private final static QuestionMapper MAPPER = new QuestionMapper();

	public final static QuestionMapper getMapper() {
		return MAPPER;
	}

	@Override
	public Question mapRow(ResultSet resultSet, int row) throws SQLException {
		Question question = new Question();
		question.setAskerId(resultSet.getLong(ASKER_ID));
		question.setAskerName(resultSet.getString(ASKER_NAME));
		question.setContent(resultSet.getString(QUESTION_CONTENT));
		question.setId(resultSet.getLong(QUESTION_ID));
		question.setFormatPublishTime(DateFormater.changeToString(resultSet.getTimestamp(PUBLISHTIME), "yyyy-MM-dd HH:mm"));
		question.setTitle(resultSet.getString(QUESTION_TITLE));
		question.setReadCount(resultSet.getInt(READ_COUNT));
		question.setReplyCount(resultSet.getInt(REPLY_COUNT));
		question.setAskerPortrait(resultSet.getString(ASKERPORTRAIT));
		return question;
	}

}
